import qs from 'qs'
import { ACCESS_TOKEN_KEY } from '@/constants'
import fileSaver from 'file-saver'

/**
 *  登录失败|注销处理
 */
export function redirectToLogin() {
  localStorage.removeItem(ACCESS_TOKEN_KEY)
  window.location.href = `/login?${qs.stringify({
    from: encodeURIComponent(location.href)
  })}`
}

/**
 * 导出excel
 */
export const saveFile = (res: Blob, name?: string) => {
  fileSaver.saveAs(res, `${name}`)
}
